"use strict";

angular.module("app").controller("positionCtrl",["$scope", "$http", "$state", "$q", "cache", function($scope, $http, $state, $q, cache){
	$scope.isLogin = cache.get("name");
	function getPosition(){
		var def = $q.defer();
		$http.get("/data/position.json?id="+$state.params.id).then(function(resp){
			$scope.position = resp.data;
//			console.log(resp);
			def.resolve(resp.data);
		}).catch(function(){
			def.reject();
		});
		return def.promise;
	}
	
	function getCompany(id){
		$http.get("/data/company.json?id="+id).then(function(resp){
			$scope.companyInfo = resp.data;
			console.log(resp);
		});
	}
	
	getPosition().then(function(data){
		getCompany(data.companyId);
	});
	
	$scope.go = function(){
		if($scope.isLogin){
			//TODO: 执行投简历数据交互
			
		}else{
			$state.go("login");
		}
	}
}]);